package edu.ccut.saturn.studio.wfg.wfgmodel;

import java.util.ArrayList;
import java.util.List;

import org.w3c.dom.Document;
import org.w3c.dom.Node;

import edu.ccut.saturn.studio.core.util.xml.SaturnW3CUtil;
import edu.ccut.saturn.studio.wfg.utils.ModelXmlUtils;

public class SaturnStartLimit{
	
	// 启动限制， 0 直接启动 ； 1 规则启动
	private String startLimitID = "0";
	
	private String logicKey = "";
	
	private List<SaturnAttribute> extendAttributeForLogicKey = new ArrayList<SaturnAttribute>();
	
	public String getStartLimitID() {
		return startLimitID;
	}

	public void setStartLimitID(String startLimitID) {
		this.startLimitID = startLimitID;
	}

	public String getLogicKey() {
		return logicKey;
	}

	public void setLogicKey(String logicKey) {
		this.logicKey = logicKey;
	}

	public List<SaturnAttribute> getExtendAttributeForLogicKey() {
		return extendAttributeForLogicKey;
	}

	public void setExtendAttributeForLogicKey(
			List<SaturnAttribute> extendAttributeForLogicKey) {
		this.extendAttributeForLogicKey = extendAttributeForLogicKey;
	}
	
	Node createNode(Document document, String nodeName){
		Node startLimitNode = document.createElement(SaturnName.KEY_NODE_ELEMENT_STARTLIMIT);
		SaturnW3CUtil.createChildNode(startLimitNode, SaturnName.KEY_NODE_NAME_ID, this.getStartLimitID());
		createChildNode(startLimitNode,document, SaturnName.KEY_STARTLIMIT_LOGICKEY);
		return startLimitNode;
	}
	
	Node createChildNode(Node node, Document document, String nodeName){
		Node logicKey = document.createElement(nodeName);
		SaturnW3CUtil.createChildNode(logicKey, SaturnName.KEY_NODE_NAME_FULLKEY, this.getLogicKey());
		for(int i = 0; i <extendAttributeForLogicKey.size(); i++ ){
			Node no = extendAttributeForLogicKey.get(i).creatNode(document, SaturnName.KEY_NODE_NAME_FULLKEY);
			logicKey.appendChild(no);
		}
		node.appendChild(logicKey);
		return node;
	}
}
